#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
# File Name: boot_menu.sh
# Author: GID5564
# Description:
# Created Time: 21/10/23-20:26:46
#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
#! /bin/bash


function __menu__(){
    wait
}


function menu_main(){
    
    local title="主菜单"
    local array_items=("1.系统版本信息","2.本地环境配置","3.搭建开发环境","4.信息安全工具","5.其它常用工具","6.Web学习工具","7.备份与恢复","8.Python项目","0.退出菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_main_entry' ${title}
    
    unset title
    unset array_items
}
function menu_main_entry(){
    local id=$1 #功能id
    case ${id} in
    1) show_system_information ;;
    2) menu_local_configuration ;;
    3) menu_develop_env;;
    4) menu_security;;
    5) menu_tools;;
    6) menu_web;;
    7) menu_backup_recovery;;
    8) menu_python_items;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_local_configuration(){
    
    local title="本地配置"
    local array_items=("1.更新源及软件包","2.安装基础软件包","3.安装配置TMOE-ZSH","4.编辑问候会话","5.编辑启动文件","6.设置本地时区","7.设置中文支持","8.创建符号连接","9.安装配置Vim","10.安装虚拟环境","11.相关文件配置","0.返回上级菜单")


    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_local_configuration_entry' ${title}
    unset title
    unset array_items

}
function menu_local_configuration_entry(){
    local id=$1 #功能id
    case ${id} in
    1) apt update && apt upgrade -y ;;
    2) menu_base_software_package ;;
    3) install_tmoe_zsh ;;
    4) edit_motd ;;
    5) edit_boot ;;
    6) set_tzdata ;;
    7) set_locales ;;
    8) create_link ;;
    9) install_vim ;;
    10) menu_virtualenv ;;
    11) menu_config_file ;;

    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_base_software_package(){
    
    local title="软件包安装"
    local array_items=("1.更新源及软件包","2.基础工具包","3.编译工具包","4.系统工具包","5.软件依赖包","0.返回上级菜单")


    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_base_software_install_entry' ${title}
    unset title
    unset array_items
}
function menu_base_software_install_entry(){
    local id=$1 #功能id
    case ${id} in
    1) apt update && apt upgrade -y ;;
    2) install_ini_dpkgs "base" ;;
    3) install_ini_dpkgs "compi" ;;
    4) install_ini_dpkgs "tool" ;;
    5) install_ini_dpkgs "others" ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_virtualenv(){
    
    local title="虚拟环境配置"
    local array_items=("1.名称列表","2.打开虚拟环境","3.新建虚拟环境","4.删除虚拟环境","5.退出当前环境-${CUR_ENV}","0.返回上级菜单")


    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_virtualenv_entry' ${title}
    
    unset title
    unset array_items
}
function menu_virtualenv_entry(){
    local id=$1 #功能id
    case ${id} in
    1) virtualenv_list ;;
    2) open_virtualenv ;;
    3) add_virtualenv
	    virtualenv_list ;;
    4) del_virtualenv
	    virtualenv_list;;
    5) quit_virtualenv;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_config_file(){
    
    local title="设置配置文件"
    local array_items=("1.当前-$(GetCurShell 'off')","2.Bash","3.vim","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_config_file_entry' ${title}
    
    unset title
    unset array_items
}
function menu_config_file_entry(){
    local id=$1 #功能id
    case ${id} in
    1) configuration_current_shell ;;
    2) configuration_file ${CONFIG_BASH};;
    3) configuration_file ${CONFIG_VIM};;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_develop_env(){
    
    local title="开发环境安装"
    local array_items=("1.Python","2.C/C++","3.JavaScript","4.MariaDB","5.PHP","6.GO","7.Java","8.Jupyter","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_develop_env_entry' ${title}
    
    unset title
    unset array_items
}
function menu_develop_env_entry(){
    local id=$1 #功能id
    case ${id} in
    1) tip "${BLUE}请输入版本号(格式如: 3.11.2): ${RESET}"
        read ver
        isok=$(echo ${ver} | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}.[0-9]\{1,3\}")
        if [[ ${isok} ]];then
            install-python ${ver}
	        success "安装完成!"
        else
            error "Python版本号格式错误!"
        fi ;;
    2) install_dpkg_packages "clang,make,build-essential,gdb,vim"
	    success "安装完成!";;
    3) install_dpkg_packages "nodejs,npm"
	    success "安装完成!";;
    4) install_dpkg_packages "mariadb,mysql_install_db"
	    success "安装完成!";;
    5) install_dpkg_packages "php,mariadb,mysql_install_db"
	    success "安装完成!";;
    6) install_dpkg_packages "golang,golang-doc"
	    success "安装完成!";;
    7) 
		tip "如果您要使用JAVA开发环境，请使用 安装常用工具 - Atilo 或其他方式安装一个GNU/Linux系统镜像，再自行搭建JAVA开发环境。";;
    8) menu_jupyter;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_jupyter(){
    
    local title="Jupyter安装配置"
    local array_items=("1.安装Jupyter","2.安装C内核","3.安装zsh内核","4.matplotlib显示中文问题","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_jupyter_entry' ${title}
    
    unset title
    unset array_items
}
function menu_jupyter_entry(){
    local id=$1 #功能id
    case ${id} in
	1)  source ${BIN_PATH}/funcs/install_jupyter.sh;;
	2)  InstallCKernel;;
	3)  InstallZshKernel;;
	4)  matplotlib_chinese_display;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_backup_recovery(){
    
    local title="备份与恢复"
    local array_items=("1.备份目录-home","2.备份目录-usr","3.备份目录-aidboot","4.自定义备份目录","5.还原系统","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    
    select_menu $array_items 'menu_backup_recovery_entry' ${title}
    
    unset title
    unset array_items
}
function menu_backup_recovery_entry(){
    local id=$1 #功能id
    case ${id} in
	1)  backup_dir "/home" ${BACKUP_PATH}
	    ;;
	2)  backup_dir "/usr" ${BACKUP_PATH}
	    ;;
	3)  backup_dir "${XSHELL_PATH}" ${BACKUP_PATH}
	    ;;
	4)  msg "${BLUE}请输入要备份的目录完整路径:${RESET}"
	    read back_path
	    msg "${BLUE}确定要备份目录 ${RESET}${YELLOW}${back_path}${RESET} ${BLUE}吗?［${RESET}${YELLOW}y|n${RESET}${BLUE}］${RESET}" 
        read -k yn
        if [[ $yn = 'y' || $yn = 'Y' ]];then
        	backup_dir "${back_path}" ${BACKUP_PATH}
        fi
	    ;;
	5)  recover_backup ${BACKUP_PATH}
	    ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_tools(){
    
    local title="常用工具"
    local array_items=("1.aptitude","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_tools_entry' ${title}
    
    unset title
    unset array_items
}
function menu_tools_entry(){
    local id=$1 #功能id
    case ${id} in
    1) handle_aptitude ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_web(){
    #git clone
    #git clone ${MYGIT}/html_doc.git ${HTML_DOC}
    UpdateDown ${HTML_DOC} "${MYGIT}/html_doc.git"
    
    local title="网络学习工具"
    local array_items=("1.代码编辑器-Jupyter","2.图表制作-DrawIo","3.代码贴图-Excalidraw","4.Kalvin在线工具","5.机器学习一","6.机器学习二","7.库文档-PyWebIO","8.前端开发","9.Aidlux文档","0.退出菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_web_entry' ${title}
    
    unset title
    unset array_items
}
function menu_web_entry(){
    local id=$1 #功能id
    case ${id} in
	1)  open_jupyter_notebook;;
	2)  WEB_DIR="${HTML_DOC}/图表制作工具"
	    open_web ${WEB_DIR};;
	3)  WEB_DIR="${HTML_DOC}/代码贴图工具"
	    open_web ${WEB_DIR};;
    4) WEB_DIR="${HTML_DOC}/Kalvin在线工具"
	    open_web ${WEB_DIR};;
	5)  WEB_DIR="${HTML_DOC}/机器学习"
	    open_web ${WEB_DIR};;
	6)  WEB_DIR="${HTML_DOC}/机器学习HTML"
	    open_web ${WEB_DIR};;
	7)  WEB_DIR="${HTML_DOC}/库文档"
	    open_web ${WEB_DIR};;
	8)  WEB_DIR="${HTML_DOC}/前端开发"
	    open_web ${WEB_DIR};;
	9)  WEB_DIR="${HTML_DOC}/aidlux文档"
	    open_web ${WEB_DIR};;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}


function menu_security(){
    
    local title="安全信息管理工具"
    local array_items=("1.SELinux","2.AppArmor","3.Fail2ban","4.ClamAV","5.Snort","6.OpenVAS","7.AIDE","8.Lynis","9.OSSEC","10.Suricata","11.Nmap","12.Wireshark","13.Metasploit","14.OpenVPN","15.GnuPG","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_security_entry' ${title}
    
    unset title
    unset array_items
}
function menu_security_entry(){
    local id=$1 #功能id
    case ${id} in
    1)  ;;
    2)  ;;
    3)  ;;
    4)  ;;
    5)  ;;
    6)  ;;
    7)  ;;
    8)  ;;    
    9)  ;;
    10)  ;;
    11)  ;;
    12)  ;;
    13)  install_metasploit;;
    14)  ;;
    15)  ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_python_items(){
    
    local title="Python项目"
    local array_items=("1.依赖包配置","2.项目开发","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_python_items_entry' ${title}
    
    unset title
    unset array_items
}
function menu_python_items_entry(){
    local id=$1 #功能id
    case ${id} in
    1) menu_dependent_package ;;
    2) menu_develop_items ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}


function menu_dependent_package(){
    
    local title="依赖包配置"
    local array_items=("1.科学计算","2.机器学习","3.深度学习","4.图像处理","5.文本处理","6.数据查看","7.音频处理","8.网络爬虫","9.数据库处理","10.文件压缩处理","11.办工自动化","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_dependent_package_entry' ${title}
    
    unset title
    unset array_items
}
function menu_dependent_package_entry(){
    local id=$1 #功能id
    case ${id} in
	1)  install_project_to_evn "ScientificComputing"
	    ;;
	2)  install_project_to_evn "Machinelearning"
	    ;;
	3)  install_project_to_evn "DeepLearning"
	    ;;
	4)  install_project_to_evn "ImageProcessing"
	    ;;
	5)  install_project_to_evn "TextProcessing"
	    ;;
	6)  install_project_to_evn "Dataviewing"
	    ;;
	7)  install_project_to_evn "AudioProcessing"
	    ;;
	8)  install_project_to_evn "WebCrawler"
	    ;;
	9)  install_project_to_evn "Database"
	    ;;
	10)  install_project_to_evn "CompressedFile"
	    ;;
	11)  install_project_to_evn "OfficeAutomation" ;;

    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_develop_items(){
    
    local title="开发项目"
    local array_items=("1.发送邮件","2.图片处理","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_develop_items_entry' ${title}
    
    unset title
    unset array_items
}
function menu_develop_items_entry(){
    local id=$1 #功能id
    case ${id} in
    1) send_html_email
     ;;
    2)  menu_image;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}



function menu_image(){
    
    local title="图片处理"
    local array_items=("1.九宫格","2.词云图","3.二维码","4.图片特效","5.去除阴影","6.图片校正","7.图像增强","8.******","9.******","10.******","11.******","12.******","13.******","14.******","15.******","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_image_entry' ${title}
    
    unset title
    unset array_items
}
function menu_image_entry(){
    local id=$1 #功能id
    case ${id} in
    1)  jiugongge;;
    2)  wordcloud;;
    3)  2dcode;;
    4)  menu_image_filter;;
    5)  remove_shadow;;
    6)  image_rectification;;
    7)  menu_image_enhancement;;
    8)  ;;    
    9)  ;;
    10)  ;;
    11)  ;;
    12)  ;;
    13)  ;;
    14)  ;;
    15)  ;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}


function menu_image_filter(){
    
    local title="图片特效"
    local array_items=("1.浮雕","2.雕刻","3.凸透镜","4.底片","5.素描","6.怀旧","7.光照","8.流年","9.油画","10.水彩画","11.黑白","12.毛玻璃","13.马赛克","14.卡通","15.去背景","16.换背景色","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_image_filter_entry' ${title}
    
    unset title
    unset array_items
}
function menu_image_filter_entry(){
    local id=$1 #功能id
    case ${id} in
    1)  filter_embossment;;
    2)  filter_carve;;
    3)  filter_convex_lens;;
    4)  filter_negative_film;;
    5)  filter_sketch;;
    6)  filter_nostalgia;;
    7)  filter_illumination;;
    8)  filter_flowingyear;;
    9)  filter_oilpaint;;
    10)  filter_stylization;;
    11)  filter_monochrome;;
    12)  filter_glass;;
    13)  filter_mask;;
    14)  filter_cartoon;;
    15)  remove_background;;
    16)  change_background_color;;
    *)  error "选择无效!"
        ;;
    esac
    unset id
}

function menu_image_enhancement(){
    
    local title="图像增强"
    local array_items=("1.浮雕","0.返回上级菜单")

    show_title $title
    show_menu $array_items
    show_end
    select_menu $array_items 'menu_image_enhancement_entry' ${title}
    
    unset title
    unset array_items
}
function menu_image_enhancement_entry(){
    local id=$1 #功能id
    case ${id} in
    1)  ;;

    esac
    unset id
}




































